package cn.iocoder.yudao.module.system.convert.examscore;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.system.controller.admin.examscore.vo.*;
import cn.iocoder.yudao.module.system.dal.dataobject.examscore.ExamScoreDO;
import cn.iocoder.yudao.module.system.dal.dataobject.examtest.ExamTestDO;
import cn.iocoder.yudao.module.system.dal.dataobject.examclass.ExamClassDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.List;

/**
 * 学生成绩 Convert
 *
 * @author 芋道源码
 */
@Mapper
public interface ExamScoreConvert {

    ExamScoreConvert INSTANCE = Mappers.getMapper(ExamScoreConvert.class);

    @Mapping(target = "id", ignore = true)
    ExamScoreDO convert(ExamScoreCreateReqVO bean);

    ExamScoreDO convert(ExamScoreUpdateReqVO bean);

    @Mapping(target = "examName", ignore = true)
    @Mapping(target = "className", ignore = true)
    ExamScoreRespVO convert(ExamScoreDO bean);

    List<ExamScoreRespVO> convertList(List<ExamScoreDO> list);

    PageResult<ExamScoreRespVO> convertPage(PageResult<ExamScoreDO> page);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "classRank", ignore = true)
    @Mapping(target = "gradeRank", ignore = true)
    @Mapping(target = "province", ignore = true)
    @Mapping(target = "firstSubject", ignore = true)
    @Mapping(target = "secondSubject", ignore = true)
    @Mapping(target = "examType", ignore = true)
    @Mapping(target = "examNo", ignore = true)
    @Mapping(target = "className", ignore = true)
    @Mapping(target = "classId", ignore = true)
    @Mapping(target = "subjectCombination", ignore = true)
    @Mapping(target = "totalScoreAssigned", ignore = true)
    @Mapping(target = "combinationRank", ignore = true)
    @Mapping(target = "schoolRank", ignore = true)
    List<ExamScoreImportExcelVO> convertList02(List<ExamScoreDO> list);

    @Mapping(target = "id", ignore = true)
    ExamScoreDO convert(ExamScoreImportExcelVO bean);

    /**
     * 转换成绩DO为响应VO，包含考试名称和班级名称
     */
    @Mapping(source = "examScore.id", target = "id")
    @Mapping(source = "examScore.createTime", target = "createTime")
    @Mapping(source = "examScore.examId", target = "examId")
    @Mapping(source = "examScore.studentId", target = "studentId")
    @Mapping(source = "examScore.studentNo", target = "studentNo")
    @Mapping(source = "examScore.studentName", target = "studentName")
    @Mapping(source = "examScore.chineseScore", target = "chineseScore")
    @Mapping(source = "examScore.mathScore", target = "mathScore")
    @Mapping(source = "examScore.englishScore", target = "englishScore")
    @Mapping(source = "examScore.physicsScore", target = "physicsScore")
    @Mapping(source = "examScore.chemistryScore", target = "chemistryScore")
    @Mapping(source = "examScore.biologyScore", target = "biologyScore")
    @Mapping(source = "examScore.politicsScore", target = "politicsScore")
    @Mapping(source = "examScore.historyScore", target = "historyScore")
    @Mapping(source = "examScore.geographyScore", target = "geographyScore")
    @Mapping(source = "examScore.russianOriginalScore", target = "russianOriginalScore")
    @Mapping(source = "examScore.russianAssignedScore", target = "russianAssignedScore")
    @Mapping(source = "examScore.russianGradeLevel", target = "russianGradeLevel")
    @Mapping(source = "examScore.russianUnionRank", target = "russianUnionRank")
    @Mapping(source = "examScore.russianSchoolRank", target = "russianSchoolRank")
    @Mapping(source = "examScore.russianClassRank", target = "russianClassRank")
    @Mapping(source = "examScore.japaneseOriginalScore", target = "japaneseOriginalScore")
    @Mapping(source = "examScore.japaneseAssignedScore", target = "japaneseAssignedScore")
    @Mapping(source = "examScore.japaneseGradeLevel", target = "japaneseGradeLevel")
    @Mapping(source = "examScore.japaneseUnionRank", target = "japaneseUnionRank")
    @Mapping(source = "examScore.japaneseSchoolRank", target = "japaneseSchoolRank")
    @Mapping(source = "examScore.japaneseClassRank", target = "japaneseClassRank")
    @Mapping(source = "examScore.spanishOriginalScore", target = "spanishOriginalScore")
    @Mapping(source = "examScore.spanishAssignedScore", target = "spanishAssignedScore")
    @Mapping(source = "examScore.spanishGradeLevel", target = "spanishGradeLevel")
    @Mapping(source = "examScore.spanishUnionRank", target = "spanishUnionRank")
    @Mapping(source = "examScore.spanishSchoolRank", target = "spanishSchoolRank")
    @Mapping(source = "examScore.spanishClassRank", target = "spanishClassRank")
    @Mapping(source = "examScore.totalScore", target = "totalScore")
    @Mapping(source = "examScore.classRank", target = "classRank")
    @Mapping(source = "examScore.gradeRank", target = "gradeRank")
    @Mapping(source = "examScore.province", target = "province")
    @Mapping(source = "examScore.firstSubject", target = "firstSubject")
    @Mapping(source = "examScore.secondSubject", target = "secondSubject")
    @Mapping(source = "examScore.examType", target = "examType")
    @Mapping(source = "examScore.examNo", target = "examNo")
    @Mapping(source = "examScore.classId", target = "classId")
    @Mapping(source = "examScore.subjectCombination", target = "subjectCombination")
    @Mapping(source = "examScore.totalScoreAssigned", target = "totalScoreAssigned")
    @Mapping(source = "examScore.combinationRank", target = "combinationRank")
    @Mapping(source = "examScore.schoolRank", target = "schoolRank")
    @Mapping(source = "examTest.examName", target = "examName")
    @Mapping(source = "examClass.className", target = "className")
    ExamScoreRespVO convert(ExamScoreDO examScore, ExamTestDO examTest, ExamClassDO examClass);

    /**
     * 转换成绩DO列表为响应VO列表，包含考试名称和班级名称
     */
    default List<ExamScoreRespVO> convertListWithRelations(List<ExamScoreDO> examScores, 
                                                           List<ExamTestDO> examTests, 
                                                           List<ExamClassDO> examClasses) {
        if (examScores == null) {
            return null;
        }
        
        return examScores.stream().map(examScore -> {
            ExamTestDO examTest = examTests.stream()
                .filter(test -> test.getId().equals(examScore.getExamId()))
                .findFirst().orElse(null);
            
            ExamClassDO examClass = examClasses.stream()
                .filter(clazz -> clazz.getId().equals(examScore.getClassId()))
                .findFirst().orElse(null);
            
            return convert(examScore, examTest, examClass);
        }).collect(java.util.stream.Collectors.toList());
    }

}
